package com.corecloud.controller.statistical;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.corecloud.entity.SysRoleEntity;
import com.corecloud.service.OtherBaseService;
import com.corecloud.service.SysRoleService;
import com.corecloud.tools.AjaxResultData;
import com.corecloud.tools.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.security.Principal;
import java.util.HashMap;
import java.util.Map;

/**
 * 统计-欢迎页
 */
@Controller
@RequestMapping("/wel")
public class WelcomeController {

	@Autowired
	private OtherBaseService otherBaseService;
	@Autowired
	private SysRoleService sysRoleService;


	/**
	 * 欢迎页地图数据
	 * @param principal
	 * @return
	 */
	@RequestMapping("/mapData")
	@ResponseBody
	public AjaxResultData mapData(Principal principal){
		try {
			AjaxResultData ard = new AjaxResultData();
			ard.setData(otherBaseService.getWelcomeMapData());
			return ard;
		}catch (Exception e){
			return new AjaxResultData(500,"操作失败,请联系管理员");
		}
	}


	/**
	 * 欢迎页操作日志统计
	 * 需处理成图表所需线形图数据
	 * @param principal
	 * @return
	 */
	@RequestMapping("/logData")
	@ResponseBody
	public AjaxResultData logData(Principal principal){
		try {
			AjaxResultData ard = new AjaxResultData();
			//回填数据
			Map<String,Object> resultMap = new HashMap<>();
			resultMap.put("logData",otherBaseService.getWelcomeLogData());
			//获取数据中每天的统计指标-用户角色
			resultMap.put("roleList",sysRoleService.getListByParas(new QueryWrapper<SysRoleEntity>().eq("is_valid",1)));
			//获取时间-从当前时间向前推七天-格式：mm-dd
			resultMap.put("weekDays",new DateUtils().getWeekDayByNow());
			ard.setData(resultMap);
			return ard;
		}catch (Exception e){
			return new AjaxResultData(500,"操作失败,请联系管理员");
		}
	}

}
